﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DUCover.Core;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NLog;

namespace DUCover.Persistence
{
    /// <summary>
    /// Handles outputting the content to files
    /// </summary>
    public static class MyFileWriter
    {
        private static Logger logger = LogManager.GetLogger("MyFileWriter");

        public static void DumpAllDeclEntity(AllDeclEntity ade)
        {
            //Dump the dynamic field store that includes information of which method modify which fields
            try
            {
                var filename = DUCoverConstants.DeclEntityFile;
                using (StreamWriter sw = new StreamWriter(filename))
                {
                    foreach (DeclEntity de in ade.DeclEntitySet)
                    {
                        sw.WriteLine(de.ToString());
                        sw.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Failed to write contents of all declared entities", ex);
            }
        }
    }
}
